package com.neu.admin;

import com.neu.config.SystemConfig;
import com.neu.service.ShoppingSystemService;
import com.neu.util.JacksonUtil;
import com.neu.util.response.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("admin/config")
@Api(description = "运费配置")
public class ShoppingSystemController {

    @Autowired
    private ShoppingSystemService shoppingSystemService;
    /**
      *获取用户配置信息
      * description:
      * Param:
      * return:
      * Author: 张智康
      * Date:
      */
    @GetMapping("/express")
    @ApiOperation(value = "查询运费配置")
    public ResponseEntity listExpress() {
        Map<String, Object> data = shoppingSystemService.listExpress();
        return BaseResponse.generateOKResponseEntity(data);
    }
    /**
      * 修改用户配置信息
      * description:
      * Param:
      * return:
      * Author: 张智康
      * Date:
      */
    @PostMapping("/express1")
    @ApiOperation(value = "运费修改")
//    public ResponseEntity updateExpress(@RequestBody String body) {
//        Map<String, String> data = JacksonUtil.toMap(body);
//        shoppingSystemService.updateConfig(data);
//        SystemConfig.updateConfigs(data);
//        return BaseResponse.generateOKResponseEntity();
//    }
    public ResponseEntity updateWx(@RequestBody Map<String,String> map){
        int flag = shoppingSystemService.updateConfig(map);
        if (flag==1){
            return BaseResponse.generateOKResponseEntity();
        }else {
            return BaseResponse.generateBadResponseEntity();
        }
    }


}
